package com.water.app.Impl.Order;

import com.water.app.Constant;
import com.water.app.Goods;
import com.water.app.Order;
import com.water.app.interfaces.Order.OrderService;
import com.water.app.mapper.OrderMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public List<Order> selectAll() {
        Integer userId = Constant.THREAD_LOCAL.get();
        return orderMapper.selectAll(userId);
    }

    @Override
    public void receiveOrder(int goodeId) {
        Integer userId = Constant.THREAD_LOCAL.get();
        orderMapper.updateStatus(goodeId,1,userId);
    }

    @Override
    public List<Order> getOrderShopGoods() {
        Integer userId = Constant.THREAD_LOCAL.get();
        return orderMapper.getOrderShopGoods(userId);
    }

    @Override
    public List<Goods> getGoodsRelease() {
        Integer userId = Constant.THREAD_LOCAL.get();
        return orderMapper.getGoodsRelease(userId);
    }

    @Override
    public List<Order> selectAllOrders(Integer userId) {
        List<Order> orders = null;
        try {
            log.info("查询订单2");
            orders = orderMapper.selectAllOrders(userId);
            log.info("orders:{}",orders);
        } catch (Exception e) {
            log.info("orders:{}1111",orders);
            throw new RuntimeException(e);
        }
        return orders;
    }
}
